<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<div id="div1" style="position: absolute;right: 0;width: 100px;height: 100px;top: 0px;background-color: #000000"></div>
<body style="height: 3000px;">
<script type="text/javascript">
    window.onload = function () {
        window.onscroll =function () {
            var oDiv = document.getElementById('div1');
            var scrollTop = document.documentElement.scrollTop||document.body.scrollTop;

            //oDiv.style.top = scrollTop+(document.documentElement.clientHeight - oDiv.offsetHeight)/2+'px';
            var t = scrollTop+(document.documentElement.clientHeight - oDiv.offsetHeight)/2;
            startMove(t);
        };
        var timer = null;
        function startMove(iTarget) {
            var oDiv = document.getElementById('div1');
            clearInterval(timer);
            timer = setInterval(function () {
                var iSpeed = (iTarget-oDiv.offsetTop)/8;
                iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);

                if(oDiv.offsetTop == iTarget){
                    clearInterval(timer);
                }else {
                    oDiv.style.top = oDiv.offsetTop+iSpeed+'px';
                }

            }, 30);
        }
    };
</script>
</body>
</html>